package com.gxa.service.impl;

import com.gxa.common.PaginationResult;
import com.gxa.mapper.StoreMapper;
import com.gxa.pojo.Branch;
import com.gxa.pojo.ClazzLibrary;
import com.gxa.pojo.Headquarters;
import com.gxa.service.StoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: zrf
 * Date: 2020/10/29 9:46
 * Description:
 * Version: V1.0
 */
@Service
public class StoreServiceImpl implements StoreService{
    @Autowired(required = false)
    private StoreMapper storeMapper;

    /**
     * 根据id查询分店信息
     *
     * @param
     * @return 实例对象
     */
    @Override
    public Branch selBreaChMag(Integer branchCode) {
        return storeMapper.selBreaChMag(branchCode);
    }

    /**
     * 查询总店信息
     *
     * @param
     * @return 实例对象
     */
    @Override
    public PaginationResult selCupro(Integer currentPage, Integer pageSize) {
        PaginationResult paginationResult = new PaginationResult();

        int parm1 = (currentPage - 1) * pageSize;
        List<Headquarters> headquartersList = storeMapper.selCupro(parm1,pageSize);
        paginationResult.setData(headquartersList);
        paginationResult.setCurrentPage(parm1);
        paginationResult.setPageSize(pageSize);
        int total = headqCont() / pageSize;
        System.out.println(headqCont());
        if(headqCont() % pageSize != 0){
            total+=1;
        }
        System.out.println(total);
        paginationResult.setTotalPage(total);
        paginationResult.setTotalSize(headqCont());
        return paginationResult;
    }

    /**
     * 根据名称查询总店信息
     *
     * @param
     * @return 实例对象
     */
    @Override
    public Headquarters selHeadqa(String headquarters_name) {
        return storeMapper.selHeadqa(headquarters_name);
    }

    /**
     * 编辑总店信息
     *
     * @param
     * @return 实例对象
     */
    @Override
    public int updateHeadq(Headquarters headquarters) {
        return storeMapper.updateHeadq(headquarters);
    }

    /**
     * 增加总店信息
     *
     * @param
     * @return 实例对象
     */
    @Override
    public int addHeadq(Headquarters headquarters) {
        return storeMapper.addHeadq(headquarters);
    }

    /**
     * 删除总店信息
     *
     * @param
     * @return 实例对象
     */
    @Override
    public int delHeadq(Integer headquartersCode) {
        return storeMapper.delHeadq(headquartersCode);
    }

    @Override
    public PaginationResult selBreach(Integer currentPage, Integer pageSize) {
        return null;
    }

//    /**
//     * 搜索所有分店信息信息
//     *
//     * @param
//     * @return 实例对象
//     */
//    @Override
//    public PaginationResult selBreach(Integer currentPage, Integer pageSize) {
//        PaginationResult paginationResult = new PaginationResult();
//        int parm1 = (currentPage - 1) * pageSize;
//        List<Branch> branchList = storeMapper.selBreach(parm1,pageSize);
//        paginationResult.setData(branchList);
//        paginationResult.setCurrentPage(parm1);
//        paginationResult.setPageSize(pageSize);
//        int total = breachCont() / pageSize;
//        System.out.println(breachCont());
//        if(breachCont(h) % pageSize != 0){
//            total+=1;
//        }
//        System.out.println(total);
//        paginationResult.setTotalPage(total);
//        paginationResult.setTotalSize(breachCont(headquartersCode));
//        return paginationResult;
//    }

    /**
     * 搜索所有类库信息信息
     *
     * @param
     * @return 实例对象
     */
    @Override
    public PaginationResult selClazzb(Integer headquartersCode, Integer currentPage, Integer pageSize) {
        PaginationResult paginationResult = new PaginationResult();
        int parm1 = (currentPage - 1) * pageSize;
        List<ClazzLibrary> clazzLibraries = storeMapper.selClazzb(headquartersCode,parm1,pageSize);
        paginationResult.setData(clazzLibraries);
        paginationResult.setCurrentPage(parm1);
        paginationResult.setPageSize(pageSize);
        int total = clazzCont(headquartersCode) / pageSize;
        System.out.println(clazzCont(headquartersCode));
        if(clazzCont(headquartersCode) % pageSize != 0){
            total+=1;
        }
        System.out.println(total);
        paginationResult.setTotalPage(total);
        paginationResult.setTotalSize(clazzCont(headquartersCode));
        return paginationResult;
    }

    /**
     * 增加分店信息
     *
     * @param
     * @return 实例对象
     */
    @Override
    public int addBranch(Branch branch) {
        return storeMapper.addBranch(branch);
    }

    /**
     * 增加类库信息
     *
     * @param
     * @return 实例对象
     */
    @Override
    public int addClazz(ClazzLibrary clazzLibrary) {
        return storeMapper.addClazz(clazzLibrary);
    }

    /**
     * 编辑类库信息
     *
     * @param
     * @return 实例对象
     */
    @Override
    public int updateClazz(ClazzLibrary clazzLibrary) {
        return storeMapper.updateClazz(clazzLibrary);
    }

    /**
     * 删除类库信息
     *
     * @param
     * @return 实例对象
     */
    @Override
    public int delClazz(Integer clazzLibraryId) {
        return storeMapper.delClazz(clazzLibraryId);
    }

    /**
     * 编辑分店信息
     *
     * @param
     * @return 实例对象
     */
    @Override
    public int updateBranch(Branch branch) {
        return storeMapper.updateBranch(branch);
    }

    /**
     * 删除分店信息
     *
     * @param
     * @return 实例对象
     */
    @Override
    public int delBranch(Integer branchCode) {
        return storeMapper.delBranch(branchCode);
    }

    /**
     * 搜索所有分店信息
     *
     * @param
     * @return 实例对象
     */
    @Override
    public List<Branch> queryBranch() {
        return storeMapper.queryBranch();
    }

    /**
     * 搜索总部code
     *
     * @param
     * @return 实例对象
     */
    @Override
    public List<Integer> selHeadqaCode() {
        return storeMapper.selHeadqaCode();
    }

    private int clazzCont(Integer headquartersCode) {
        return storeMapper.clazzCont(headquartersCode);
    }

    private int breachCont(Integer headquartersCode) {
        return storeMapper.breachCont(headquartersCode);
    }

    private int headqCont() {
        return storeMapper.headqCont();
    }


}
